-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
TYP: use overload to refine return type of reset_index #33519
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TYP: use overload to refine return type of reset_index #33519
Conversation
self, | ||
level: Optional[Union[Hashable, Sequence[Hashable]]] = None, | ||
drop: bool = False, | ||
*, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to combine Literal and overload here instead of this? I don’t think this is 100% accurate if a user provides inplace=False
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can't use Literal til Python 3.8 or unless we adopt typing extensions.
If we pass inplace=False
the return type will match the second signature and so the return type will be the Union. This is not inaccurate and no change from the status quo.
If we don't pass an inplace
argument, the return type will be DataFrame and additional asserts, casts or ignores aren't needed. This is an improvement from the status quo.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whether explicitly passing inplace=False
or just sticking with the default signature the expected return type shouldn't be different, which is what is being introduced here. The ideal overload should be something like "return None if inplace=True, otherwise return a DataFrame".
While the current approach may appease most type checking it introduces unexpected behavior when providing the inplace keyword; would rather try to integrate a Literal type or actually deprecate inplace.
self, | ||
level: Optional[Union[Hashable, Sequence[Hashable]]] = None, | ||
drop: bool = False, | ||
*, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whether explicitly passing inplace=False
or just sticking with the default signature the expected return type shouldn't be different, which is what is being introduced here. The ideal overload should be something like "return None if inplace=True, otherwise return a DataFrame".
While the current approach may appease most type checking it introduces unexpected behavior when providing the inplace keyword; would rather try to integrate a Literal type or actually deprecate inplace.
can't use Literal yet.
can't do this till 2.0 closing to clear queue as requested changes not actionable. can potentially reopen depending on outcome of #33274 |
@simonjayhawkins @WillAyd is there a consensus on how to move forward here? |
So I wouldn't object to vendoring typing_extensions and doing this with Literal values - @simonjayhawkins do you have any particular thoughts on that? As is though I think this creates as many nuances as it solves, so not a huge fan of going forward in current state |
No description provided.